#ifndef __MQTT_FUN_H__
#define __MQTT_FUN_H__

#include <stdint.h>

#define _host "192.168.123.9"              //服务器IP 你的虚拟机服务器IP
#define _port      1883                    //端口
#define _interval  180                     //保持链接时间s
#define _client_id "soonIoT"               //连接到mqtt服务器的id
#define _username  "soon"                  //这个id下的使用的用户名
#define _password  "soontest"              //密码
#define _checkstatus 100                   //100s 检查下状态

typedef enum 
{
    MQTT_ACK_CONNET = 0,
    MQTT_ACK_SOCKET_ERR = -101,
    MQTT_ACK_CONNET_BADACK = -102,
    MQTT_ACK_NOACK = -103,

}MQTT_ACK;

/*
  Description: 
      MQTT Message callback function pointer type.

  Parameter:
      topic    --  MQTT Topic
      message  -- MQTT Message

  Return Value:
      NA
*/
typedef void (*PMQTTMessageCallback)(char* topic, char* message);


/*
  Description: 
      MQTT Status callback function pointer type.

  Parameter:
      status    --  MQTT status

  Return Value:
      NA
*/
typedef void (*PMQTTStatusCallback)(int status);

/*
  Description: 
       initialize MQTT process context.

  Parameter:
      None

  Return Value:
      0     -- Success
      other -- Failure
*/
int MQTT_Init(void);


/*
  Description: 
       initialize MQTT process context.

  Parameter:
      socket: the returen of transport_open()

  Return Value:
      0     -- Success
      other -- Failure
*/
int MQTT_Connect(void);
/*
  Description: 
      To register callback functions for MQTT.

  Parameter:
      sub_topic    -- subscribe topic name of MQTT
      callback     -- callback function for MQTT message

  Return Value:
      0     -- Success
      other -- Failure
*/
int MQTT_Subscribe_Topic(char* sub_topic, PMQTTMessageCallback callback);

/*
  Description: 
      To UnSubscribe a Topic for MQTT.

  Parameter:
      unsub_topic    -- unsubscribe topic name of MQTT

  Return Value:
      0     -- Success
      other -- Failure
*/
int MQTT_UnSubscribe_Topic(char* unsub_topic);
/*
  Description: 
      To Public a MQTT topic.

  Parameter:
      topic    -- public topic name of MQTT
      message  -- MQTT message

  Return Value:
      NA
*/
void MQTT_Public_Topic(char* topic, char* message);

/*
  Description: 
      MQTT Ping callback.

  Parameter:
	  status :callback function for MQTT

  Return Value:
      NA
*/
void MQTT_PingREQ_Callback(PMQTTStatusCallback status);

/*
  Description: 
      To unregister callback functions for a MQTT topic.

  Parameter:
      name -- target topic name of MQTT topic

  Return Value:
      None
*/
void MQTT_Disconnect(void);

/*
  Description: 
      To close MQTT message process task.

  Parameter:
      None

  Return Value:
      None
*/
void MQTT_Close(void);
#endif
